using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Data.SqlClient;

namespace Acms.SqlDal
{
    public class SearchTermDal : Base 
    {
        public SearchTermDal()
        { 
        }

        public enum Fields
        {
            Id, 
            SiteId, 
            Term, 
            Count
        }

        protected override void ReadRecord(Hashtable table, SqlDataReader reader)
        {
            GetReaderValue<int>(Fields.Id, reader, table);
            GetReaderValue<int>(Fields.SiteId, reader, table);
            GetReaderValue<string>(Fields.Term, reader, table);
            GetReaderValue<int>(Fields.Count, reader, table);
        }

        public Hashtable[] GetAllBySiteId(int siteId)
        {
            SqlCommand cmd = CreateCommand("GetAllBySiteId");
            AddInputParameter(cmd, "SiteId", siteId, System.Data.SqlDbType.Int);
            return ExecuteGetCollection(cmd);
        }

        public void Update(int siteId, string term, ref int idOut, ref int countOut)
        {
            SqlCommand cmd = CreateCommand("Put");
            AddInputParameter(cmd, "SiteId", siteId, System.Data.SqlDbType.Int);
            AddInputParameter(cmd, "Term", term, System.Data.SqlDbType.VarChar, 50);
            AddOutputParameter(cmd, "IdOut", System.Data.SqlDbType.Int);
            AddOutputParameter(cmd, "CountOut", System.Data.SqlDbType.Int);

            ExecuteCommand(cmd);

            idOut = GetOutputValue<int>(cmd, "IdOut");
            countOut = GetOutputValue<int>(cmd, "CountOut");
        }
    }
}
